package org.snail.activemq.converter;

import org.springframework.jms.support.converter.MessageConversionException;
import org.springframework.jms.support.converter.SimpleMessageConverter;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

/**
 *  activeMq 延迟执行类
 */
public class DelayMessageConverter extends SimpleMessageConverter {
    /** deliveryType */
    private String deliveryType = "JMS_JBOSS_SCHEDULED_DELIVERY";

    /** schedDeliveryTime */
    private long schedDeliveryTime = 2000;

    public void setDeliveryType(String deliveryType) {
        this.deliveryType = deliveryType;
    }

    public void setSchedDeliveryTime(long schedDeliveryTime) {
        this.schedDeliveryTime = schedDeliveryTime;
    }

    @Override
    public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
        Message message = super.toMessage(object, session);
        message.setLongProperty(this.deliveryType, System.currentTimeMillis() + this.schedDeliveryTime);
        return message;
    }
}